package pl.edu.agh.mgr.hotel.ws.configuration;

import java.util.Calendar;
import java.util.List;

import pl.edu.agh.mgr.hotel.entities.Hotel;
import pl.edu.agh.mgr.hotel.entities.ServiceDescription;
import pl.edu.agh.mgr.hotel.hibernate.HibernateDAO;

public class WSInitializer {

	private final String hotelName;
	private final String wsName;
	private final String wsAddress;

	public WSInitializer(String hotelName, String wsName, String wsAddress) {
		this.hotelName = hotelName;
		this.wsName = wsName;
		this.wsAddress = wsAddress;
	}

	public ServiceDescription initializeHotel() {
		HibernateDAO<Hotel> hotelDAO = new HibernateDAO<Hotel>(Hotel.class);
		List<Hotel> hotelList = hotelDAO
				.get("from Hotel hotel where hotel.name = '" + hotelName + "'");
		Hotel hotel = null;
		if (!hotelList.isEmpty()) {
			hotel = hotelList.get(0);

			return new ServiceDescription(hotel.getName(), hotel.getCountry(),
					hotel.getProvince(), hotel.getCity(), hotel.getStreet(),
					hotel.getAddress(), hotel.getHotelType(),
					hotel.getRoomTypes(), wsAddress, wsName,
					hotel.getDataLevel(), Calendar.getInstance().getTime());

		}

		return new ServiceDescription();
	}
}
